package pe.edu.upc.dew.pharma.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

public class PharmaException extends SimpleMappingExceptionResolver {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5347062744522633769L;
	
	private static final Log logger = LogFactory.getLog(PharmaException.class);

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.handler.SimpleMappingExceptionResolver#doResolveException(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)
	 */
	@Override
	protected ModelAndView doResolveException(HttpServletRequest request,
			HttpServletResponse response, Object object, Exception ex) {
		if(logger.isDebugEnabled())
		{
			logger.debug(ToStringBuilder.reflectionToString(request));
			logger.debug(ToStringBuilder.reflectionToString(response));
			logger.debug(ToStringBuilder.reflectionToString(object));
			logger.debug(ToStringBuilder.reflectionToString(ex));
		}
		if(logger.isErrorEnabled())
		{
			logger.error("Error en la Aplicaccion Pharma, mostrando traza...", ex);
		}		
		return super.doResolveException(request, response, object, ex);
	}	
}
